<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 							
		<%@ include file="../jslib/jquerylib.jsp" %>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	$(document).ready(function(){
	             
			    var gridname='';
			    if(<%=request.getParameter("flag")%>=='0'){
				   gridname =  "样品接收列表";
				}else{ 
				   gridname = "样品归还列表";
				}
				//高级搜索需要的js
				buttonStatus=1;
				$("#flip").click(function(){
					if(buttonStatus==1){
						$("#panel").slideToggle("slow");
						$("#flip").toggleClass("btnStatus2");
						buttonStatus=1;
					}
					else{
						$("#panel").slideUp("slow");
						$("#flip").toggleClass("btnStatus2");
					}
			 });
				 //高级搜索结束
	
					$("#gridTable").jqGrid({
						url:'<%=request.getContextPath() %>/codeReviewActionNew!queryGwmSampleManageList.action?flag=<%=request.getParameter("flag")%>&samplestate='+$("#samplestate").val(),
						datatype: "json",
						height: 450,
						width: 710, 
						autowidth: true, 
						colNames:['序号','委托识别号','任务名称','委托单位','委托人','申请日期','联系电话','T_TASKID','样品状态'],
						colModel:[
								{name:'ID',index:'ID', width:60, key:true, sorttype:"int",hidden:true,hidedlg:true}, 
								{name:'T_WEITUOHAO',index:'T_WEITUOHAO', width:150},								
								{name:'T_TASKNAME',index:'T_TASKNAME', width:130},
								{name:'T_WEITUODANW',index:'T_WEITUODANW', width:120},
								{name:'USERNAME',index:'USERNAME', width:110},
								{name:'T_SHENQINGRQ',index:'T_SHENQINGRQ', width:110},
								{name:'T_TELEPHONE',index:'T_TELEPHONE', width:150},
								{name:'T_TASKID',index:'T_TASKID', width:110,hidden:true},
								{name:'T_SAMPLESTATE',index:'T_SAMPLESTATE', width:80},
					],
					shrinkToFit:false,
					sortname:'ID',
					sortorder:'asc',
					viewrecords:true,
					multiselect: true, // 是否显示复选框
					multiboxonly : true, 
					//gridview: true,  //提升速度
					rownumbers: true,//显示行号
					rownumWidth: 30, //行号的宽度
					rowNum:15,
					rowList:[15,20,50,200,500],
					toolbar: [false,"top"],
					jsonReader: {
						root:"rows",		// 数据行（默认为：rows）
						page: "page",  	// 当前页
						total: "total",  // 总页数
						records: "records",  // 总记录数
						repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
					},
					prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
					pager:"#gridPager",
					subGrid: true,
				    subGridRowExpanded: function(subgrid_id, row_id) {
					   var rowData = $("#gridTable").getRowData(row_id); 
				       var subgrid_table_id;
				       subgrid_table_id = subgrid_id+"_t";
				       var row = jQuery("#gridTable").jqGrid('getRowData',row_id);
				       jQuery("#"+subgrid_id).html("<table id='"+subgrid_table_id+"' class='scroll'></table>");
				       jQuery("#"+subgrid_table_id).jqGrid({
				    	   url:common_basePath+'codeReviewActionNew!querySampleDetailBytaskId.action?flag=<%=request.getParameter("flag")%>&taskId='+rowData.T_TASKID+'&temp='+Math.round(Math.random()*10000),
				    	    datatype: "json", 
							colNames:['ID','样品名称','样品编号','样品数量','批次号/规格型号','生产商'],
							colModel:[
								{name:'ID',index:'ID', width:100,key:true,hidden:true, sorttype:"int"} ,
								{name:'T_SAMPLENAME',index:'T_SAMPLENAME', width:100},
								{name:'T_SAMPLENO',index:'T_SAMPLENO', width:170},
								{name:'T_SAMPLECOUNT',index:'T_SAMPLECOUNT', width:100},
								{name:'T_PICI',index:'T_PICI', width:100},
								{name:'T_MANUFACTURER',index:'T_MANUFACTURER', width:180},
								], 
							jsonReader: {
								root:"rows",		// 数据行（默认为：rows）
								page: "page",  	// 当前页
								total: "total",  // 总页数
								records: "records",  // 总记录数
								repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
							},  
							shrinkToFit:false,
						    height:"auto", 
						    multiselect: true, 
						    width:700,
							rowNum:500,
							sortname:'ID',
							sortorder:'asc'
				       });
				   },
					 caption: gridname
			});
			 if(<%=request.getParameter("flag")%>=='0'){
			    jQuery("#gridTable").jqGrid("hideCol","T_SAMPLESTATE");
			 }
	}); 
	
	//执行大小
	function doResize() { 
		var ss = getPageSize(); 
		//alert(ss.WinH);
		
			 $("#gridTable").jqGrid('setGridHeight', ss.WinH-245);
			 $("#gridTable").jqGrid('setGridWidth', ss.WinW-30); 
			} 
	
	 
		//查询
		function gridSearch(){
			var shenqingrq = jQuery("#shenqingrq").val();
            var endrq =  jQuery("#endrq").val(); 
            var weituodanwei = $.trim(jQuery("#weituodanwei").val());
            var shibiehao = $.trim(jQuery("#shibiehao").val());
            var weituoren = $.trim(jQuery("#weituoren").val());
            var samplestate = $("#samplestate").val();
            var params = {  
                        "shenqingrq" : shenqingrq,                           
                        "endrq" : endrq,
                        "weituodanwei" : encodeURIComponent(weituodanwei),
                        "shibiehao":encodeURIComponent(shibiehao),
                        "weituoren":encodeURIComponent(weituoren),
                        "samplestate":samplestate
                         };
            var postData = $("#gridTable").jqGrid("getGridParam", "postData");
            $.extend(postData, params);
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/codeReviewActionNew!queryGwmSampleManageList.action?flag=<%=request.getParameter("flag")%>'
			}).trigger("reloadGrid", [{page:1}]);
        } 
       
		//刷新
		function refreshIt(){
			//resetSearch();
			jQuery("#gridTable").jqGrid('setGridParam',
			{
				url:'<%=request.getContextPath() %>/codeReviewActionNew!queryGwmSampleManageList.action?flag=<%=request.getParameter("flag")%>&samplestate='+$("#samplestate").val()
			}).trigger("reloadGrid", [{page:1}]);
		    
		}
		function reload(){
			refreshIt();
		}
		//清空
		function reset(){
			jQuery("#shenqingrq").val("");
			jQuery("#endrq").val("");
			jQuery("#weituodanwei").val("");
			jQuery("#shibiehao").val("");	
			jQuery("#weituoren").val("");	
			jQuery("#samplestate").val("0");	
		}
		
		
	        
	      //页面上的刷新按钮
			function shuaXin(){
				reset();
				gridSearch();
			}
	  
	   function sampleAccept(flag){
	      var taskIds = [];
	      var sampleId = [];
	      var s = $("#gridTable").jqGrid('getGridParam', 'selarrrow') + "";
	      if(!s){
	         alert("请选择数据");
	         return false;
	      }
	      var ids = s.split(",");
	      for ( var i = 0; i < ids.length; i++) {
			var id = ids[i];
			var row = $("#gridTable").jqGrid('getRowData', id);
			var childGrid = $("#gridTable_"+id+"_t").jqGrid('getGridParam', 'selarrrow') + "";
		    if(childGrid=='undefined'){
		       taskIds.push(row.T_TASKID);
		    }
		    else if(!childGrid){
		       var ids1 = $("#gridTable_"+id+"_t").jqGrid('getDataIDs')+"";
		       sampleId.push(ids1);
		    }
		    else{
		      sampleId.push(childGrid);
		    }
		 }
		 if(flag==0){
		   var datas = window.showModalDialog("<%=request.getContextPath()%>/view/gwm_sampleManage_accept.jsp?ids="+taskIds.join()+"&sampleIds="+sampleId.join()+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=600px;scroll:no");
	     }else{
	       var datas = window.showModalDialog("<%=request.getContextPath()%>/view/gwm_sampleManage_return.jsp?ids="+taskIds.join()+"&sampleIds="+sampleId.join()+"&temp="+Math.round(Math.random()*10000),'',"dialogWidth=900px;dialogHeight=600px;scroll:no");
	     }
	     refreshIt();
	   }   
	</script>	
	</head>
	<body>
	<form action="" method="post" id="form1">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
		   		<td>
			 		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			   		<tr>
			   		    <td width="7%" height="35" align="right">委托单位：</td>
			        	<td width="13%"><input type="text" name="weituodanwei" id="weituodanwei" class="search_InputText" style="width:99%;" /> </td>
			       	 	<td width="7%" height="35" align="right">识别号：</td>
			        	<td width="13%"><input type="text" name="shibiehao" id="shibiehao"  class="search_InputText" style="width:99%;" /> </td>
			        	<td width="7%" height="35" align="right">申请日期：</td>
			        	<td width="13%"><input type="text" name="shenqingrq" id="shenqingrq" onClick="WdatePicker()" class="search_InputText" style="width:99%;"/></td>
			        	<td width="5%" height="35" align="right">至：</td>
			        	<td width="13%"><input type="text" name="endrq" id="endrq"  onClick="WdatePicker()" class="search_InputText" style="width:99%;" /> </td>
			        	<td width="20%" align="center"><input type="button" name="button" id="button" value="查询" onclick="gridSearch()" class="search_Btn" />
			      			&nbsp;<input type="reset" name="button2" id="button2" value="清空" onclick="reset()" class="search_Btn" />
			      		</td>
			      	</tr>
			      	
			      </table>
			      <div id="panel" style="display:none;">
			      <table width="100%" border="0" cellspacing="0" cellpadding="0" class="font12Black_B">
			      	<tr>
			      	   <td width="7%" height="35" align="right">委托人：</td>
			        	<td width="13%"><input type="text" name="weituoren" id="weituoren"  class="search_InputText" style="width:99%;" value=""/></td>
			        	<%
		         	    if("1".equals(request.getParameter("flag"))){
		         	    %>
			        	<td width="10%" height="35" align="right">样品状态：</td>
			        	<td  colspan="2">
			        	 <select id="samplestate" name="samplestate" style="width:150px">
			        	    <option value="0">未归还</option>
			        	    <option value="1">已归还</option>
			        	 </select>
			        	</td>
			        	<%
			        	 }else{
			        	%>
			        	<td width="5%" height="35" align="right"></td>
			        	<td width="13%" colspan="3">
			        	<%
			        	} %>
			        	<td width="7%" height="35" align="right"></td>
			        	<td width="13%"></td>
			       	 	<td width="7%" height="35" align="right"></td>
			        	<td width="13%"></td>
			       	 	<td width="20%" align="center">
			      		</td>
			      	</tr>
			      	
			    </table>
			    </div>		    
		  		</td>
		 	  </tr>
		      <tr>
                <td align="right" height="9" class="sclinebotBg"></td>
	          </tr>
		      <tr>
			    <td width="92%" align="right"><div class="btnStatus" id="flip"></div></td>
			    <td width="8%">&nbsp;</td>
			  </tr>
			</table>
			<table style="width: 100%;" class="tableCont">
				<tr>
					<td height="25" valign="top">
		         	<%
		         	   if("0".equals(request.getParameter("flag"))){
		         	 %>
		         	 <input id="add"    type='button' value='样品接收' onclick="sampleAccept(0)" class='button_b' />
		         	 <%} 
		         	  else{
		         	 %>
		         	 <input id="add"    type='button' value='样品归还' onclick="sampleAccept(1)" class='button_b' />
		         	 <%} %>
				</tr>
				<tr>
					<td colspan="4" style="padding-top:8px;">
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
				</tr>
		   </table>
	</form>
	</body>
</html>
